<template>
	<view class="user-car">
		<view class="car-goods-list" v-if="carList.length">
			<view class="car-item" v-for="(data,index) in carList" :key="index">
				<view class="car-item-goods" v-for="(item,goodsIndex) in data.goods_sku" :key="goodsIndex">
					<!-- <u-checkbox v-model="item.checked" size="36" active-color="#141414" @change="choseSingleItem($event,index)"></u-checkbox> -->
					<view class="goods-info" @click.stop="goProInfo(item.goods_id,item.store_id,item.type)">
						<view class="goods-info-tag" v-if="item.goods_type==3 || item.goods_type==8">换购</view>
						<image :src="item.img" mode="aspectFill"></image>
						<view class="goods-info-text">
							<view class="goods-name">{{item.goods_name}}</view>
							<view class="goods-sku">
								<text v-if="item.color">{{item.color}}</text>
								<text v-if="item.size">{{item.size}}</text>
								<text v-if="item.lining">{{item.lining}}</text>
							</view>
							<view class="goods-send" v-if="item.send_name">货期：{{item.send_name}}</view>
							<view class="goods-price">
								<view class="goods-price-left">￥<text>{{item.retail_price}}</text></view>
								<view class="goods-price-right">数量：{{item.num}}件</view>
							</view>
						</view>
					</view>
					<view class="goods-info-num">
						<!-- <u-number-box
							@minus="CalculationPrice($event,item.cart_id)"
							@plus="CalculationPrice($event,item.cart_id)"
							:min="item.coefficient_num?item.coefficient_num:1"
							:step="item.coefficient_num?item.coefficient_num:1"
							v-model="item.num"
							:input-width="75"
							:input-height="72" bg-color="#FFFFFF"
							:disabled="item.goods_type==2?true:false">
						</u-number-box> -->
					</view>
				</view>
				<view class="car-item-goods" v-for="(item,groupIndex) in data.group" :key="item.group_id">
				<!-- <u-checkbox v-model="item.checked" size="36" active-color="#141414" @change="choseSingleItem($event,index)"></u-checkbox> -->
				<view class="goods-info" @click.stop="goGroupInfo(item.group_id,item.is_house)">
					<image :src="item.image_thumb" mode="aspectFill"></image>
					<view class="goods-info-text">
						<view class="goods-name">{{item.group_name}}</view>
						<view :class="['goods-sku',{active: item.lookGoods}]" @click.stop="showGoods(index,groupIndex,item.group_name,item.goods)">已选{{item.goods.length}}件商品 <u-icon name="arrow-down"></u-icon>
						</view>
						<view class="goods-price">
							<view class="goods-price-left">￥<text>{{item.retail_price}}</text></view>
							<view class="goods-price-right">数量：{{item.num}}件</view>
						</view>
					</view>
				</view>
				<!-- <view class="goods-info-num">
					<u-number-box
						@minus="CalculationPrice"
						@plus="CalculationPrice"
						:disabled="true"
						:min="item.coefficient_num?item.coefficient_num:1"
						:step="item.coefficient_num?item.coefficient_num:1"
						v-model="item.num"
						:input-width="75"
						:input-height="72" bg-color="#FFFFFF">
					</u-number-box>
				</view> -->
			</view>
			</view>
		</view>
		<block v-else>
			<pt-nothing :fixed="true" :custom="true">
				<view class="car-empty">
					<view class="icon"><image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png"></image></view>
					<view class="car-empty-tit">该用户购物车为空</view>
				</view>
			</pt-nothing>
		</block>
		<uni-popup ref="groupGoods" type="bottom" class="car-group-goods" @change="showGoodsPopChange">
			<view class="groupGoods">
				<view class="groupGoods-tit">
					<view class="group-name">{{title}}</view>
					<u-icon name="close-circle" size="40" @click="closeGroupGoods"></u-icon>
				</view>
				<view class="groupGoods-list-box">
					<scroll-view scroll-y class="groupGoods-list">
						<view class="groupGoods-item" v-for="(item,index) in groupGoodsList" :key="index">
							<image :src="item.img" mode="aspectFill"></image>
							<view class="goods-info-text">
								<view class="goods-name">{{item.goods_name}}</view>
								<view class="goods-sku">
									<text v-if="item.color">{{item.color}}</text>
									<text v-if="item.size">{{item.size}}</text>
									<text v-if="item.lining">{{item.lining}}</text>
								</view>
								<view class="goods-price">
									<view class="goods-price-left">￥<text>{{item.retail_price}}</text></view>
									<view class="goods-info-num">x{{item.num}}</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user_id: '',
				carList: [],
				title: '',
				groupGoodsList: []
			};
		},
		onLoad(options) {
			this.user_id = options.user_id
			this.init()
		},
		methods: {
			init(){
				this.$u.api.CartItems({user_id: this.user_id}).then(res => {
					this.carList = res.datas.on_sale
				})
			},
			goProInfo(goods_id,store_id,type){
				if(type==6){
					uni.navigateTo({
						animationDuration: 500,
						url: '/pages/light/light-product-info?isMerchant=true&goods_id='+goods_id
					})
					return
				}
				if(store_id!=1){
					getApp().goProInfo(goods_id,true)
				}else{
					getApp().goProInfo(goods_id)
				}
			},
			// 查看套餐商品
			showGoods(index,groupIndex,group_name,groupGoodsList){
				this.$refs.groupGoods.open()
				this.title = group_name
				this.groupGoodsList = groupGoodsList
				if(!this.carList[index].group[groupIndex].lookGoods){
					this.$set(this.carList[index].group[groupIndex],'lookGoods',true)
				}else{
					this.$set(this.carList[index].group[groupIndex],'lookGoods',false)
				}
			},
			// 关闭套餐商品弹窗
			closeGroupGoods(){
				this.$refs.groupGoods.close()
			},
			showGoodsPopChange(e){
				if(!e.show){
					this.carList.forEach(item => {
						if(item.group){
							item.group.forEach(data => {
								data.lookGoods = false
							})
						}
					})
				}
			},
			goGroupInfo(group_id,group_type){
				if(group_type==2){
					uni.navigateTo({
						animationDuration: 500,
						url: '/pages/package/house-info?group_id='+group_id
					})
				}else{
					uni.navigateTo({
						animationDuration: 500,
						url: '/pages/package/n98-info?group_id='+group_id
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	.user-car{
		.car-goods-list{
			background-color: #FFF;
			.car-item-goods{
				display: flex;
				align-items: center;
				padding: 20rpx 30rpx 50rpx;
				position: relative;
				.goods-info{
					flex: 1;
					min-width: 0;
					display: flex;
					align-items: flex-start;
					position: relative;
					.goods-info-tag{
						position: absolute;
						z-index: 1;
						left: 0;
						right: 0;
						width: 60rpx;
						height: 36rpx;
						line-height: 36rpx;
						background-color: #FEF7F2;
						border-radius: 4rpx 0px 4rpx 0px;
						font-size: 22rpx;
						color: #F59359;
					}
					image{
						width: 210rpx;
						height: 210rpx;
						margin-right: 30rpx;
					}
					.goods-info-text{
						flex: 1;
						min-width: 0;
						.goods-name{
							font-size: 28rpx;
							color: #141414;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}
						.goods-price{
							margin-top: 20rpx;
							display: flex;
							align-items: center;
							justify-content: space-between;
							.goods-price-left{
								font-size: 24rpx;
								color: #141414;
								text{
									font-size: 32rpx;
								}
							}
						}
						.goods-sku{
							margin-top: 15rpx;
							color: #757575;
							font-size: 22rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							text{
								margin-right: 20rpx;
							}
							/deep/ .u-icon{
								transition: all .5s;
								margin-left: 20rpx;
							}
							&.active{
								/deep/ .u-icon{
									transform: rotate(-180deg);
								}
							}
						}
						.goods-send{
							font-size: 24rpx;
							color: #F59359;
							margin-top: 20rpx;
						}
					}
				}
				.goods-info-num{
					position: absolute;
					right: 30rpx;
					bottom: 50rpx;
				}
			}
		}
		.groupGoods{
			background-color: #FFF;
		}
		.groupGoods-tit{
			display: flex;
			align-items: center;
			height: 100rpx;
			padding: 0 30rpx;
			border-bottom: solid 2rpx #EFEFEF;
			.group-name{
				flex: 1;
				min-width: 0;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				margin-right: 30rpx;
			}
		}
		.groupGoods-list-box{
			height: 800rpx;
			position: relative;
		}
		.groupGoods-list{
			position: absolute;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
		}
		.groupGoods-item{
			display: flex;
			padding: 30rpx;
			border-bottom: solid 1px #EFEFEF;
			image{
				width: 175rpx;
				height: 175rpx;
				margin-right: 30rpx;
				border: solid 2rpx #EFEFEF;
			}
			.goods-info-text{
				flex: 1;
				min-width: 0;
				.goods-name{
					font-size: 28rpx;
					color: #141414;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.goods-price{
					margin-top: 30rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.goods-price-left{
						font-size: 24rpx;
						color: #141414;
						text{
							font-size: 32rpx;
						}
					}
				}
				.goods-sku{
					margin-top: 30rpx;
					color: #757575;
					font-size: 22rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					text{
						margin-right: 20rpx;
					}
					/deep/ .u-icon{
						transition: all .5s;
						margin-left: 20rpx;
					}
					&.active{
						/deep/ .u-icon{
							transform: rotate(-180deg);
						}
					}
				}
			}
		}
	}
</style>
